package com.xinqi.modules.course.clazz.manager.impl;

import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.xinqi.common.base.error.CommonErrors;
import com.xinqi.common.mybatis.data.service.impl.BaseServiceImpl;
import com.xinqi.modules.course.clazz.domain.ClassEntity;
import com.xinqi.modules.course.clazz.manager.ClassManager;
import com.xinqi.modules.course.clazz.mapper.ClassMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Objects;

/**
 * 班级表管理层实现
 *
 * @author: system
 * @date: 2023/10/25
 */
@Service
@RequiredArgsConstructor
public class ClassManagerImpl extends BaseServiceImpl<ClassMapper, ClassEntity> implements ClassManager {
    /**
     * 根据id查询 班级表数据
     */
    @Override
    public ClassEntity findById(Long id) {
        CommonErrors.BAD_REQUEST.check(Objects.nonNull(id), "ID不能为空");
        return getById(id);
    }

    /**
     * 根据id更新 班级表数据，重写
     */
    public boolean updateById(ClassEntity entity) {
        return SqlHelper.retBool(getBaseMapper().updateById(entity));
    }

    /**
     * 根据id删除 班级表数据
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteById(Long id) {
        CommonErrors.BAD_REQUEST.check(Objects.nonNull(id), "ID不能为空");
        return this.removeById(id);
    }

}
